package net.crowdloud.server.DatabaseAccess.problem;

import java.util.ArrayList;
import java.util.List;

public class ConvertDatabaseToProblem {

	public static List<net.crowdloud.shared.entities.Problem> getProblems(
			List<Problem> problemsDatabase) {

		List<net.crowdloud.shared.entities.Problem> problems = new ArrayList<net.crowdloud.shared.entities.Problem>();

		for (Problem problemDatabase : problemsDatabase) {

			net.crowdloud.shared.entities.Problem problem = new net.crowdloud.shared.entities.Problem();
			problems.add(getProblem(problemDatabase));
		}

		return problems;
	}

	public static net.crowdloud.shared.entities.Problem getProblem(
			Problem databaseProblem) {

		net.crowdloud.shared.entities.Problem problem = new net.crowdloud.shared.entities.Problem();

		if (databaseProblem.getProblemID() != null) {

			problem.setProblemID(databaseProblem.getProblemID().getId());
		}

		if (databaseProblem.getDescription() != null) {

			problem.setDescription(databaseProblem.getDescription().getValue());
		}

		if (databaseProblem.getTags() != null) {

			problem.setTags(databaseProblem.getTags().getValue());
		}

		return problem;
	}
}
